import pytest

from page.page_in import PageIn
from tools.get_driver import GetDriver
from tools.get_log import GetLog
from tools.read_yaml import read_yaml

logger = GetLog.get_logger()


class TestAppLogin:

    # 1.初始化
    def setup_class(self):
        # 1.获取driver
        driver = GetDriver.get_app_driver()
        # 2.通过统一入口对象获取PageAppCsdnLogin对象
        self.login = PageIn(driver).page_get_PageAppCsdnLogin()

    # 2.结束
    def teardown_class(self):
        GetDriver.quit_app_driver()

    # 3.csdn登录测试业务方法
    @pytest.mark.parametrize('phone,pwd', read_yaml('app_csdn_login.yaml'))
    def test_app_login(self, phone, pwd):
        # 调用app登录业务方法
        self.login.page_app_csdn_login(phone, pwd)
        # 断言
        try:
            assert self.login.page_get_account_name()
        except Exception as e:
            # 1.日志
            logger.error(e)
            # 2.截图
            self.login.base_get_image()
            # 3.抛异常
            raise


